package com.liuym.login.common;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author LiuYiMing
 */
@Component
public class ThreadPoolRunner {
    private static Logger logger = LoggerFactory.getLogger(ThreadPoolRunner.class);

    private static ExecutorService commonExecutor;

    @PostConstruct
    private void init() {
       /* ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
                .setNameFormat("demo-pool-%d").build();
*/
        //Common Thread Pool
       /* commonExecutor = new ThreadPoolExecutor(5, 200,
                0L, TimeUnit.MILLISECONDS,
                new LinkedBlockingQueue<Runnable>(1024), new ThreadPoolExecutor.AbortPolicy());*/

        //commonExecutor.shutdown();
        commonExecutor = Executors.newFixedThreadPool(10);
        logger.info("全局公共线程池初始化成功...");
    }

    public static ExecutorService getExecutorService() {
        return commonExecutor;
    }
}
